namespace SimpleWebServices.Web.Mvc
{
    using System;
    using SimpleWebServices.Configuration;
    using SimpleWebServices.Data;
    using SimpleWebServices.Web.Routing;

    public sealed class ImplicitUriConverter<T> : UriConverter, IConvertUri
            where T : IRecord
    {
        public ImplicitUriConverter(Type controller)
            : base(controller)
        {
        }

        public AbsoluteUri Urn
        {
            get
            {
                AbsoluteUri result = null;

                ResourcePath resource = this.ToResourcePath(HttpContextFactory.Current.Request.Path);
                if (null != resource)
                {
                    result = RepositoryConfiguration.ToUrn<T>(resource.Name);
                }

                return result;
            }
        }
    }
}